package org.pray.activity.observe;

import java.util.HashSet;
import java.util.Set;

public class Listen {
    Set<Observer> listener = new HashSet<>();

    // 添加观察的对象
    public void addObserver(Observer observer) {
        listener.add(observer);
    }

    // 执行变化回调方法
    public void doCallBack() {
        listener.forEach(Observer::update);
    }

    public static void main(String[] args) {
        Listen listen = new Listen();
        listen.addObserver(() -> {
            System.out.println("A");
        });
        listen.addObserver(() -> {
            System.out.println("B");
        });
        listen.doCallBack();
    }
}
